/**
 * @file app\led\led_Lisi.c
 *
 * Copyright (C) 2023
 *
 * dp_key.c is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author zhuodada
 *
 * @encoding utf-8
 */

/*---------- includes ----------*/
#include "device.h"
#include "gpio_group.h"
#include "protocol_mobus.h"
#include "resources.h"
#include "soft_timer.h"
#include "storage.h"

/*---------- macro ----------*/
#define TAG "Lisi_LED"

/*---------- type define ----------*/
/*---------- variable prototype ----------*/
/*---------- function prototype ----------*/
/*---------- variable ----------*/
void* dev_led_Lisi;
static volatile unsigned short temp_led_sat = 0;
struct storage_led_struct* temp_led_struct = NULL;
/*---------- function  ----------*/
static void _timer_expired(timer_handle_t timer) {
    gpio_group_describe_t* pdesc = NULL;
    static volatile unsigned char cflag_ = 0, cflag_times = 0, led_sta = 1;
    static volatile unsigned char pir_flag = 0, pir_person_times = 0;
    static volatile unsigned short die_time_cnt = 0;
    if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_START) {
        if (cflag_ == 0) {
            led_sta = 1;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
#if DEV_KEY_NUM == 2
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
            cflag_ = 1;
        }
        else {
            cflag_ = 0;led_sta = 0;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
#if DEV_KEY_NUM == 2
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
            cflag_times++;
        }
        if (cflag_times > 8) {
            cflag_ = 0;
            cflag_times = 0;
            no_storage.led_temp_variable.dev_work_mode = LED_MODE_UPDATA;
            temp_led_struct = (struct storage_led_struct*)storage_get(STORAGE_AREA_LIGHT_MODE);
            assert(temp_led_struct);
            temp_led_sat = temp_led_struct->LisicarD_struct.background;
        }
    }
    else if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_CLEAN) {
        led_sta = 0;
#if DEV_KEY_NUM == 4
        device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX3 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
        device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX3 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
#if DEV_KEY_NUM == 2
        device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
        device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif  
        device_ioctl(dev_led_Lisi, (0xFF << 8) | IOCTL_GROUP_GET, (void*)&pir_flag);
        if (pir_flag == 1 || temp_led_sat != temp_led_struct->LisicarD_struct.background)
        {
            temp_led_sat = temp_led_struct->LisicarD_struct.background;
            no_storage.led_temp_variable.dev_work_mode = LED_MODE_UPDATA;
            die_time_cnt = 0;
        }
    }
    else if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_LOCAL) {
    }
    else if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_UPDATA) {
        no_storage.led_temp_variable.dev_work_mode = LED_MODE_WORK;
#if DEV_KEY_NUM == 4
        led_sta = no_storage.LisicarD_Temp.s1_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
        led_sta = no_storage.LisicarD_Temp.s2_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
        led_sta = no_storage.LisicarD_Temp.s3_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX3 | IOCTL_GROUP_SET, (void*)&led_sta);
        led_sta = no_storage.LisicarD_Temp.s4_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
        led_sta = no_storage.LisicarD_Temp.s1_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
        led_sta = no_storage.LisicarD_Temp.s2_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
        led_sta = no_storage.LisicarD_Temp.s3_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX3 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
#if DEV_KEY_NUM == 2
        led_sta = no_storage.LisicarD_Temp.s1_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
        led_sta = no_storage.LisicarD_Temp.s2_led_sat;
        device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
        if (no_storage.LisicarD_Temp.s1_led_sat == 0)
        {
            led_sta = 1;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif           
#if DEV_KEY_NUM == 2
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif         
        }
        else {
            led_sta = 0;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 2
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
        }
        if (no_storage.LisicarD_Temp.s2_led_sat == 0)
        {
            led_sta = 1;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
#if DEV_KEY_NUM == 2
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
        }
        else {
            led_sta = 0;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 2
            device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
        }
        if (no_storage.LisicarD_Temp.s3_led_sat == 0)
        {
            led_sta = 1;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
        }
        else {
            led_sta = 0;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
        }
        if (no_storage.LisicarD_Temp.s4_led_sat == 0)
        {
            led_sta = 1;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
        }
        else {
            led_sta = 0;
#if DEV_KEY_NUM == 4
            device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif      
        }
    }
    else if (no_storage.led_temp_variable.dev_work_mode == LED_MODE_WORK) {
        if (no_storage.LisicarD_Temp.pir_enable_flag == 1)
        {
#if DEV_KEY_NUM == 4
            led_sta = no_storage.LisicarD_Temp.s1_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s2_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s3_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX3 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s4_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            led_sta = no_storage.LisicarD_Temp.s1_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s2_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s3_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX3 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
#if DEV_KEY_NUM == 2
            led_sta = no_storage.LisicarD_Temp.s1_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s2_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
            if (no_storage.LisicarD_Temp.s1_led_sat == 0)
            {
                led_sta = 1;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif           
#if DEV_KEY_NUM == 2
                device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif         
            }
            else {
                led_sta = 0;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 2
                device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
            }
            if (no_storage.LisicarD_Temp.s2_led_sat == 0)
            {
                led_sta = 1;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
#if DEV_KEY_NUM == 2
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
            }
            else {
                led_sta = 0;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 2
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
            }
            if (no_storage.LisicarD_Temp.s3_led_sat == 0)
            {
                led_sta = 1;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
            }
            else {
                led_sta = 0;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
            }
            if (no_storage.LisicarD_Temp.s4_led_sat == 0)
            {
                led_sta = 1;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
            }
            else {
                led_sta = 0;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif      
            }
            device_ioctl(dev_led_Lisi, (0xFF << 8) | IOCTL_GROUP_GET, (void*)&pir_flag);
            if (pir_flag == 1 || temp_led_sat != temp_led_struct->LisicarD_struct.background)
            {
                pir_person_times++;
                temp_led_sat = temp_led_struct->LisicarD_struct.background;
                if (pir_person_times > 5)
                {
                    pir_person_times = 0;
                    no_storage.LisicarD_Temp.pir_keep_flag = pir_flag;
                }
                die_time_cnt = 0;
            }
            else
            {
                if (die_time_cnt < 30 * 17)
                    die_time_cnt++;
                else {
                    pir_person_times = 0;
                    no_storage.led_temp_variable.dev_work_mode = LED_MODE_CLEAN;
                    return;
                }
            }
        }
        else
        {
#if DEV_KEY_NUM == 4
            led_sta = no_storage.LisicarD_Temp.s1_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s2_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s3_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX3 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s4_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
            led_sta = no_storage.LisicarD_Temp.s1_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s2_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s3_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX3 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
#if DEV_KEY_NUM == 2
            led_sta = no_storage.LisicarD_Temp.s1_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX1 | IOCTL_GROUP_SET, (void*)&led_sta);
            led_sta = no_storage.LisicarD_Temp.s2_led_sat;
            device_ioctl(dev_led_Lisi, GROUP_INDEX2 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif
            if (no_storage.LisicarD_Temp.s1_led_sat == 0)
            {
                led_sta = no_storage.LisicarD_Temp.backgroud_led;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif             
#if DEV_KEY_NUM == 2
                device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif         
            }
            else
            {
                led_sta = 0;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif   
#if DEV_KEY_NUM == 2
                device_ioctl(dev_led_Lisi, GROUP_INDEX4 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif   
            }
            if (no_storage.LisicarD_Temp.s2_led_sat == 0)
            {
                led_sta = no_storage.LisicarD_Temp.backgroud_led;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
#if DEV_KEY_NUM == 2
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif   
            }
            else
            {
                led_sta = 0;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
#if DEV_KEY_NUM == 2
                device_ioctl(dev_led_Lisi, GROUP_INDEX5 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif   
            }
            if (no_storage.LisicarD_Temp.s3_led_sat == 0)
            {
                led_sta = no_storage.LisicarD_Temp.backgroud_led;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
            }
            else
            {
                led_sta = 0;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX7 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
#if DEV_KEY_NUM == 3
                device_ioctl(dev_led_Lisi, GROUP_INDEX6 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
            }
            if (no_storage.LisicarD_Temp.s4_led_sat == 0)
            {
                led_sta = no_storage.LisicarD_Temp.backgroud_led;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif    
            }
            else
            {
                led_sta = 0;
#if DEV_KEY_NUM == 4
                device_ioctl(dev_led_Lisi, GROUP_INDEX8 | IOCTL_GROUP_SET, (void*)&led_sta);
#endif       
            }
        }
    }
}

void app_led_Lisi_poll(void) {
    void* proc_timer;

    dev_led_Lisi = resources_get("dev_led_Lisi");
    assert(dev_led_Lisi);

    /* create a timer for proc polling */
    proc_timer = soft_timer_create("Led_LisiTimer", SFTIM_MODE_REPEAT,
        __ms2ticks(62), NULL, _timer_expired);
    assert(proc_timer);
    soft_timer_start(proc_timer);
    /*say hi */
    xlog_tag_message(TAG, "Initialize successfully\n");
}
